Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

284
Vistas
JSON Parse error: Unexpected identifier "undefined"

i just switched to a mac today and i noticed the JSON.parse that works on other browsers, throws this error on safari.

Unhandled Promise Rejection: SyntaxError: JSON Parse error: Unexpected identifier "undefined"

This is the JSON response from my PHP code

   {"dataPointsX": "[\"31 Jan\",\"01 Feb\",\"02 Feb\",\"03 Feb\",\"04 Feb\",\"05 Feb\",\"06 Feb\"]", "dataPointsY": "[\"0\",\"0\",\"7287\",\"24572\",\"30657\",\"27865\",\"0\"]", "dataPoints2Y": "[\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\"]"}

This is my Javascript code

$.get('chartdata.php', async function (res) {
   console.log(res)
   var res = JSON.parse(res);
});

Please help

UPDATE

I have updated my PHP to echo this

{"dataPointsX":["31 Jan","01 Feb","02 Feb","03 Feb","04 Feb","05 Feb","06 Feb"],"dataPointsY":["0","0","7287","24572","30632","27820","0"],"dataPoints2Y":["0","0","0","0","0","0","0"]}

It works on chrome, safari still throwing this error

Unhandled Promise Rejection: SyntaxError: JSON Parse error: Unexpected identifier "undefined"

Console.log(JSON.parse(res)) shows this on chrome

dataPoints2Y: (7) ['0', '0', '0', '0', '0', '0', '0']
dataPointsX: (7) ['31 Jan', '01 Feb', '02 Feb', '03 Feb', '04 Feb', '05 Feb', '06 Feb']
dataPointsY: (7) ['0', '0', '7287', '24572', '30489', '27744', '0']
[[Prototype]]: Object
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It looks like your PHP code is JSON encoding content that's already JSON encoded, maybe something like this:

$points = ['31 Jan', '01 Feb', '03 Feb'];
echo json_encode(['dataPointsX' => json_encode($points)]);

This yields the oddly quoted string:

{"dataPointsX":"[\"31 Jan\",\"01 Feb\",\"03 Feb\"]"}

You only want to call json_encode() once:

$points = ['31 Jan', '01 Feb', '03 Feb'];
echo json_encode(['dataPointsX' => $points]);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda